#流量背景js


#转发的数据
transferData={}

#开始
@.gotaobao = ->
	saveUserData()
	delCook()
	closeOthers()

	#ajax setting
	ajaxSetting =
		dataType:'json'
		data:$('form').serialize()
		#type:'POST'
		error:gotaobao
		success: (data)->
			if data and data.proxy
				#设置代理服务器
				config =
					mode: "fixed_servers"
					rules:
						proxyForHttp:data.proxy
						bypassList:cdn
				chrome.proxy.settings.set {value: config, scope: 'regular'}
				
				#保存搜索信息
				transferData['searchData']=
					'keywords': data.keyword
					'sellername':data.sellername
				#进入
				chrome.tabs.create url:'http://www.taobao.com',active:false
				messenger.setSearchData transferData
				messenger.init()
			else
				messenger.finish()
				noProxy()
			#通知
			if data.msg
				notification = webkitNotifications.createNotification data.msg[0],data.msg[1],data.msg[2]
				notification.show()
				setTimeout(->
					notification.close()
				,30000)
			#错误码
			if data.errno
				messenger.finish()
				switch data.errno
					when 1
						$('#pwLabel').show()
	$.ajax "#{serverUrlPre}Visit/task",ajaxSetting
	false

#listen 监听消息
#chrome.extension.onRequest.addListener( (request, sender, sendResponse)->
#	if request.searchData
#		#获取搜索数据
#		sendResponse transferData
#)

